package com.arch.bigdata.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.regionserver.BloomType;

import java.io.IOException;

/**
 * @author pizhihui
 * @date 2024-06-05 11:06
 */
public class HbaseAdmin {


    public static void main(String[] args) throws IOException {

        Configuration conf = HBaseConfiguration.create();

        Connection connection = ConnectionFactory.createConnection(conf);

        Admin admin = connection.getAdmin();


        TableDescriptor tableDescriptor = TableDescriptorBuilder
                .newBuilder(TableName.valueOf("test-1"))
                .setColumnFamily(
                        ColumnFamilyDescriptorBuilder.newBuilder("info".getBytes())
                        .setMaxVersions(2)
                        .setBlocksize(512)
                                .setBloomFilterType(BloomType.ROWCOL)
                                .build())

                .build();


        byte[] bytes = TableDescriptorBuilder.toByteArray(tableDescriptor);

        admin.createTable(tableDescriptor);

        admin.close();
        connection.close();

    }

}
